#include "head.h"

// cd
int to_cd(messenger_t* msg, int sock_fd, MYSQL* mysql)
{
    // 切割参数
    char* path = msg->args;
    char* cmd = path;
    while(*cmd != '&') ++cmd;
    *cmd++ = '\0';

    // 得到用户的id // 解密 TOKEN
    int uid = 0;
    l8w8jwt_uid(msg->token, &uid);
    
    // 查看有无这个文件夹
    char dir_path[100] = {0};
    if(strcmp(path, "/") == 0)
        sprintf(dir_path, "%s%s", path, cmd);
    else
        sprintf(dir_path, "%s/%s", path, cmd);
    if(is_have_dir(mysql, dir_path, uid))
    {
        send(sock_fd, "succeed", 7, MSG_NOSIGNAL);
        return 0;
    }

    send(sock_fd, "failed", 6, MSG_NOSIGNAL);
    return 0;
    

}